﻿#pragma once
#include<SFML/Graphics.hpp>
#include <vector>
#include "../../libcat/include/cat-interaction.hpp"

#include "../../libcat/include/util/json.h"

class standard {
	struct key_save{
		std::vector<int> keys;
		bool isShow = false; 
		bool isLastShow = false;
		unsigned int LastShowCount = 0;
		sf::Time record;
	};
public:
	static standard* GetInstance();

	static void ReleaseInstance();

	void Init(Json::Value cfg);

	void Updata(Json::Value cfg);

	void Draw(void* _window);

	void Release();

	void OnMouseMove(int x,int y);

	void OnForceMouseMove(int x, int y);

	void OnMouseClick(const cat_mouse_click_event* event, bool key_up);

	void OnKeyPress(const int vk, bool key_up);

protected:
	standard();

	~standard();

private:
	void drawCat(sf::RenderTexture &_window);
	void drawKey(sf::RenderTexture &_window);
	void drawHand(sf::RenderTexture &_window);
	void drawFace(sf::RenderTexture &_window);
	void playSound();
	void playMotion();
	void playExpression();

	void drawline(sf::RenderTexture &_window, std::vector<double> pss2, int red_value, int green_value, int blue_value);

	Json::Value mouse_leftkey_value, 
		mouse_rightkey_value, 
		mouse_sidekey_value, 
		stopemoticon_value, 
		stopsound_value;

	bool isInit;

	double mouse_x, mouse_y;
	bool mouse_horizontal_flip;
	bool mouse_vertical_flip;
	bool motion_keep;
	float mousespeed;
	bool sound_keep;
	bool l2d_random_motion;
	bool l2d_random_expression;

	int offset_x, offset_y;				//图片文件偏移值
	int hand_offset_x, hand_offset_y;	//手整体偏移值
	int windowWidth, windowHeight;
	int horizontal, vertical;

	int renderWindowWidth, renderWindowHeight;
	sf::RenderTexture renderTexture;
	sf::Sprite renderSprite;

	double scale;
	double l2d_correct;
	double l2d_offset_x, l2d_offset_y;

	bool is_mouse_force_move;

	//arm lines color  右手轮廓的rgb值
	int red_value;
	int green_value;
	int blue_value;

	//workarea
	int top_left;
	int right_bottom;

	int mouse_state = 0;

	//window
	double letter_x, letter_y, s_height, s_width;

	//live2d
	bool isLive2d;

	sf::Clock key_clock;
	sf::Sprite bg,
		cat,
		device, 
		mouse_left,
		mouse_right, 
		mouse_side, up;
	sf::Texture atextex;				//右手纹理

	std::map<int, bool> states;

	std::map<std::string, key_save> left_hands_down;
	std::map<std::string, key_save> keys;
	std::map<std::string, key_save> faces;
	std::map<std::string, key_save> sounds;
	std::map<std::string, key_save> motions;
	std::map<std::string, key_save> expression;
};



